from time import sleep

from selenium.webdriver.common.by import By

from base import Base

class Base():
    def __init__(self):
        cap = {
            "platformName": "Android",
            "deviceName": "emulator-5554 ",
            "appPackage": "com.xiachufang",
            "appActivity": "com.xiachufang.activity.home.HomeActivity",
            "noReset": True
        }
        os.system('adb root')
        self.driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub',cap)
        self.driver.implicitly_wait(25)
        sleep(10)

    def find_ele(self, loc):
        try:
            if type(loc) == str:
                return self.driver.find.element_by_android_uiautonator(loc)
            else:
                return self.driver.find_element(*loc)
        except Exception as e:
            print("报错信息")
            print("未提供变量信息")